<template>
    <div class="list" ref="wrapper">
      <div>
        <div class="area">
          <div class="title">当前城市</div>
          <div class="button_list">
            <div class="button_wrapper">
              <div class="button">
                <!--
                {{$store.state.city}}
                -->
                {{currentCity}}
              </div>
            </div>

          </div>
        </div>
        <div class="area">
          <div class="title">热门城市</div>
          <div class="button_list">
            <div class="button_wrapper" v-for="(item,index) in hotCities" :key="index" @click="handleCityClick(item.name)">
              <div class="button">{{item.name}}</div>
            </div>
          </div>
        </div>
        <div class="area" v-for = "(item,key) in cities" :key="key" :ref="key">
          <div class="title">{{key}}</div>
          <div class="item_list">
            <div class="item" v-for="(innerItem,key) in item" :key="key" @click="handleCityClick(innerItem.name)">{{innerItem.name}}</div>
          </div>
        </div>

      </div>
    </div>
</template>
<script>
import Bscroll from 'better-scroll'
import { mapState } from 'vuex'
export default {
  name: 'CityList',
  props: {
    cities: Object,
    hotCities: Array,
    letters: Array,
    letter: String
  },
  computed: {
    ...mapState({
      currentCity: 'city'
    })
  },
  methods: {
    handleCityClick (city) {
      this.$store.commit('changeCity', city)
      this.$router.push('/')
    }
  },
  watch: {
    letter () {
      console.log(this.letter)
      const element = this.$refs[this.letter][0]
      console.log(element)
      this.scroll.scrollToElement(element)
    }
  },
  mounted () {
    this.scroll = new Bscroll(this.$refs.wrapper)
  }
}
</script>
<style scoped lang="stylus">
.list{
  position:absolute;
  left:0;
  right:0;
  top:1.58rem;
  bottom:0;
  overflow:hidden
}
.title
  height:.54rem;
  padding-left:.2rem;
  background:#eee;
  color:#666;
  line-height:.54rem;
  border-bottom:.01rem solid #ccc
  border-top: .01rem solid #ccc;

.button_list
  padding:.1rem .6rem .1rem .2rem;
  overflow:hidden;
  .button_wrapper
    float:left;
    width:33.33%
    .button
      margin:.1rem
      padding:.1rem 0
      border:.02rem solid #ccc;
      text-align:center
      border-radius:.06rem
.item_list
  .item
    line-height:.76rem;
    padding-left:.2rem;
    border-bottom:.01rem solid #ccc

</style>
